/*
 * @Author: CPS
 * @Date: 2020-07-19 09:09:33
 * @Last Modified by: CPS
 * @Last Modified time: 2020-07-19 21:22:35
 * @Projectname Electron-fileWatcher
 * @Filename readPdf.js
 */
'use strict'
const fs = require('fs');
const path = require('path')
/**
 * Gets the file size.
 *
 * @param      {number}  total   The total
 * @param      {string}  unit    The unit
 * @return     {number}  The file size.
 */
function getFileSize(fileSize) {
  if (fileSize < 1024) {
    return fileSize + 'B';
  } else if (fileSize < (1024 * 1024)) {
    let temp = fileSize / 1024;
    temp = temp.toFixed(2);
    return temp + 'KB';
  } else if (fileSize < (1024 * 1024 * 1024)) {
    let temp = fileSize / (1024 * 1024);
    temp = temp.toFixed(2);
    return temp + 'MB';
  } else {
    let temp = fileSize / (1024 * 1024 * 1024);
    temp = temp.toFixed(2);
    return temp + 'GB';
  }
}

/**
 * 读取 docx格式 当作zip进行获取
 *
 * @param      {<type>}        zipTar  The zip tar
 * @return     {(string|zip)}  { description_of_the_return_value }
 */
function readPdf(tar) {
  // 判断格式是否pdf
  if (path.extname(tar).toLowerCase() !== '.pdf') return

  let tarInfo = fs.lstatSync(tar);
  console.log(tarInfo)
  return tarInfo
}

if (require.main === module) {
  let p = 'D:/CPS/MyProject/Electron-fileWatcher/资料/扶绥新宁海螺水泥有限责任公司专用码头工程防洪评价报告（报批稿）--.pdf'
  let res = readPdf(p)
}



module.exports = readPdf